package com.eClass.dados;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JOptionPane;

import oracle.jdbc.pool.OracleDataSource;

public class ConectarOracle {

	static final String URL = "jdbc:oracle:thin:@localhost";
	private Connection conn;
	private Statement stmt;
	private CallableStatement csmt;
	private String user = "system";
	private String password = "system";

	public ConectarOracle() throws ClassNotFoundException {

		try {
			OracleDataSource ds = new OracleDataSource();
			ds.setURL(URL);
			ds.getConnection(user, password);
			conn = ds.getConnection(user, password);
			stmt = conn.createStatement();
		} catch (SQLException sqlex) {
			JOptionPane.showMessageDialog(null, sqlex.getMessage(), "ERRO!",
					JOptionPane.ERROR_MESSAGE);
		}
	}

	public ResultSet select(String query) {
		try {
			return stmt.executeQuery(query);
		} catch (SQLException sqlex) {
			JOptionPane.showMessageDialog(null, sqlex.getMessage(), "ERRO!",
					JOptionPane.ERROR_MESSAGE);
			return null;
		}
	}

	public Connection getConn() {
		return conn;
	}

	public Statement getStmt() {
		return stmt;
	}

	public CallableStatement getCstmt() {
		return csmt;
	}

}
